export default {
	//时间倒推转换
	backTime(day) {
		if (day == 'all') {
			return {
				queryStartTime: uni.$u.timeFormat(new Date(-1), 'yyyy-mm-dd hh:MM:ss'),
				queryEndTime: uni.$u.timeFormat(false, 'yyyy-mm-dd hh:MM:ss')
			}
		}
		const now = new Date()
		const back = new Date(now.setDate(now.getDate() - day))
		let item = {
			queryStartTime: uni.$u.timeFormat(back, 'yyyy-mm-dd') + " 23:59:59",
			queryEndTime: uni.$u.timeFormat(false, 'yyyy-mm-dd hh:MM:ss')
		}
		// console.log(item)
		return item
	},
	//返回图标
	getSrc(node) {
		let src = ''
		switch (node.partName) {
			case '屋面工程':
				src = "/static/public_icons/house.png"
				break;
			case '公共走道、楼梯间、电梯厅':
				src = "/static/public_icons/public.png"
				break;
			case '首层大堂':
				src = "/static/public_icons/building.png"
				break;
			case '地下室':
				src = "/static/public_icons/underground.png"
				break;
			case '外立面':
				src = "/static/public_icons/out.png"
				break;
			case '景观园林':
				src = "/static/public_icons/tree.png"
				break;
			case '市政管网':
				src = "/static/public_icons/net.png"
				break;
			default:
				src = "/static/public_icons/house.png"
				break;

		}
		return src
	},
	getHouseSrc(node) {
		let src = ''
		switch (node.partName) {
			case '客厅':
				src = "/static/selected_icons/selected-3.png"
				break;
			case '走道':
				src = "/static/selected_icons/selected-7.png"
				break;
			case '餐厅':
				src = "/static/selected_icons/selected-1.png"
				break;
			case '厨房':
				src = "/static/selected_icons/selected-2.png"
				break;
			case '儿童房':
				src = "/static/selected_icons/selected-5.png"
				break;
			case '主卧':
				src = "/static/selected_icons/selected-6.png"
				break;
			case '客卧':
				src = "/static/selected_icons/selected-4.png"
				break;
			case '主卫':
				src = "/static/selected_icons/pix1.png"
				break;
			case '客卫':
				src = "/static/selected_icons/pix2.png"
				break;
			case '玄门':
				src = "/static/selected_icons/pix5.png"
				break;
			case '书房':
				src = "/static/selected_icons/pix3.png"
				break;
			case '阳台':
				src = "/static/selected_icons/pix4.png"
				break;
			default:
				src = "/static/selected_icons/pix5.png"
				break;

		}
		return src
	},
	//返回node列表
	backNodeArray(_node) {
		for (let i = 0; i < _node.length; i++) {
			_node[i]._src = this.getSrc(_node[i])
		}
		return _node
	},
	//返回node列表
	backHouseNodeArray(_node) {
		for (let i = 0; i < _node.length; i++) {
			_node[i]._src = this.getHouseSrc(_node[i])
		}
		return _node
	},
	//获取  estateID  paraentID 下绑定的 节点
	async getPartInfoByParentIdAndEstateId(_data) {
		const data = await uni.$H.get('/realEstatePart/getPartInfoByParentIdAndEstateId', _data, {
			authCode: true
		})
		if (data.status === 0) {
			if (data.body.length != 0) {
				let temp = (data.body)
				return temp
			} else {
				// uni.$showMsg("未绑定")
				return false
			}
		} else {
			uni.$showMsg(data.message)
		}
		return false
	},
	//单项提交进度
	async pushProgress(params) {
		// createTime (string, optional): 创建时间 ,
		// estateId (string, optional): 地产或房产id ,
		// images (string, optional): 图片列表 ,
		// partId (string, optional): 部分id ,
		// photographer (string, optional): 拍摄者 ,
		// progressId (string, optional): 进度id ,
		// progressStatus (integer, optional): 审核状态 1 -未审核 2-通过审核 3-审核失败 ,
		// progressValue (integer, optional): 进度
		console.log("push")
		console.log(params)
		let _push_form = {}
		_push_form.attributes = params.attributes
		_push_form.images = params.images
		_push_form.partId = params.partId
		_push_form.createTime = params.createTime
		_push_form.progressStatus = params.progressStatus
		_push_form.photographer = uni.getStorageSync('userName')
		_push_form.progressValue = params.progressValue
		_push_form.estateId = params.estateId

		const data = await uni.$H.post('/progress/addProgress', _push_form, {
			authCode: true
		})
		if (data.status !== 0) {
			return false
		} else {
			return true
		}
	},
	async updateProgress(params) {
		// createTime (string, optional): 创建时间 ,
		// estateId (string, optional): 地产或房产id ,
		// images (string, optional): 图片列表 ,
		// partId (string, optional): 部分id ,
		// photographer (string, optional): 拍摄者 ,
		// progressId (string, optional): 进度id ,
		// progressStatus (integer, optional): 审核状态 1 -未审核 2-通过审核 3-审核失败 ,
		// progressValue (integer, optional): 进度
		console.log("push")
		console.log(params)
		let _push_form = {}
		_push_form.images = params.images
		_push_form.partId = params.partId
		_push_form.createTime = params.createTime
		_push_form.progressStatus = params.progressStatus
		_push_form.photographer = params.photographer
		_push_form.progressValue = params.progressValue
		_push_form.estateId = params.estateId
		_push_form.progressId = params.progressId
		const data = await uni.$H.post('/progress/updateProgress', _push_form, {
			authCode: true
		})
		if (data.status !== 0) {
			return false
		} else {
			return true
		}
	},
	//上传进度组
	pushProgressArray(array) {
		let flag = 0
		for (let i = 0; i < array.length; i++) {
			if (!this.pushProgress(array[i])) {
				uni.$showMsg('提交失败，请稍后重试')
				break
			}
			flag++
		}
		return flag == array.length ? true : false
	},
	//单项提交问题
	async pushQuestion(params) {
		// discoveryTime (string, optional): 发现时间 ,
		// estateId (string, optional): 房产或地产id ,
		// estimatedProcessingTime (string, optional): 预计处理时间 ,
		// faultId (string, optional): 问题类别 ,
		// handlerUserId (string, optional): 处理人id ,
		// issueImages (string, optional): 图片信息 ,
		// issueTags (string, optional),
		// issuesDesc (string, optional): 问题描述 ,
		// issuesStatus (integer, optional): 0-待上传 1-未审核 2-已通过 3-未通过 ,
		// issuesType (integer, optional): 1-质量问题 2-安全问题 ,
		// partId (string, optional): 问题部分 ,
		// projectName (string, optional): 项目名称 ,
		// qualityId (string, optional): 质量问题id ????
		console.log("push")
		console.log(params)
		let _push_form = {}
		_push_form.discoveryTime = params.discoveryTime
		_push_form.issueTags = params.issueTags.toString()
		_push_form.issueLocation = params.issueLocation
		_push_form.issuesType = params.issuesType
		_push_form.estimatedProcessingTime = params.estimatedProcessingTime
		// _push_form.partId = params.partId
		_push_form.partId = params.partId
		_push_form.issuesStatus = params.issuesStatus
		_push_form.faultId = params.faultId
		// _push_form.photographer = uni.getStorageSync('userName')
		_push_form.handlerUserId = params.handlerUserId
		_push_form.estateId = params.estateId
		_push_form.issuesDesc = params.issuesDesc
		_push_form.issueImages = params.issueImages
		const data = await uni.$H.post('/qualityIssue/addQualityIssue', _push_form, {
			authCode: true
		})
		if (data.status !== 0) {
			return false
		} else {
			return true
		}
	},
	//上传进度组
	pushQuestionArray(array) {
		let flag = 0
		for (let i = 0; i < array.length; i++) {
			if (!this.pushQuestion(array[i])) {
				uni.$showMsg('提交失败，请稍后重试')
				break
			}
			flag++
		}
		return flag == array.length ? true : false
	},
	//默认进度列表
	progressData() {
		return [{
			value: 10,
			partName: '10%'
		}, {
			value: 20,
			partName: '20%'
		}, {
			value: 30,
			partName: '30%'
		}, {
			value: 40,
			partName: '40%'
		}, {
			value: 50,
			partName: '50%'
		}, {
			value: 60,
			partName: '60%'
		}, {
			value: 70,
			partName: '70%'
		}, {
			value: 80,
			partName: '80%'
		}, {
			value: 90,
			partName: '90%'
		}, {
			value: 100,
			partName: '100%'
		}]
	},

	//获取问题列表
	async getQL() {
		const data = await uni.$H.get('/constant/getByType', {
			type: 5
		}, {
			authCode: true
		})
		if (data.status === 0) {
			if (data.body.length != 0) {
				return data.body
			} else {
				return false
			}

		} else {
			uni.$showMsg(data.message)
		}
		return false
	},
	// getSafeList() {
	// 	//获取所有
	// }，


}
